﻿//
// Library.cs: Represents a library of artists.
//
// Copyright 2010 Michael Goethe
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Serialization;

namespace S9PalCommon.ArtistLibrary
{
    /// <summary>
    /// Represents a library of artists.
    /// </summary>
    [Serializable]
    public class Library
    {
        #region Fields

        const String c_libraryDirectory = "Library";
        const String c_libraryDataFileName = "artistlibrary.dat";
        const String c_albumArtPrefix = "AlbumArt-";
        const String c_albumArtExtension = ".jpg";

        SortedList<String, Artist> artists = new SortedList<string, Artist>();

        #endregion

        #region Constructors

        /// <summary>
        /// Create a library object.
        /// </summary>
        public Library()
        {
            artists = new SortedList<String,Artist>(1);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Get the extenstion used for saving album art.
        /// </summary>
        public String AlbumArtExtension
        {
            get
            {
                return c_albumArtExtension;
            }
        }

        /// <summary>
        /// Get the prefix used in saving album art.
        /// </summary>
        public String AlbumArtPrefix
        {
            get
            {
                return c_albumArtPrefix;
            }
        }

        /// <summary>
        /// Get or set the artists in the library.
        /// </summary>
        public SortedList<String, Artist> Artists
        {
            get
            {
                return artists;
            }
            set
            {
                artists = value;
            }
        }

        /// <summary>
        /// Get the relative path of the library directory.
        /// </summary>
        public String LibraryDirectory
        {
            get
            {
                return c_libraryDirectory;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Get the names of all the artists in the library.
        /// </summary>
        /// <returns>Array of artist names in the library.</returns>
        public String[] GetArtistNames()
        {
            List<String> artistList = new List<String>();

            for (int i = 0; i < Artists.Count; i++)
                artistList.Add(Artists.ElementAt(i).Value.Name);

            return artistList.ToArray();
        }

        /// <summary>
        /// Serialize the library to a file.
        /// </summary>
        public void SaveLibrary()
        {
            Helper.SerializeObject<Library>(c_libraryDataFileName, this);
        }

        #endregion
    }
}
